package cn.itcast.web.servlet;


import cn.itcast.daomain.user;
import cn.itcast.service.UserService;
import cn.itcast.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;


@WebServlet("/modifyServlet")
public class modifyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        HttpSession  session = request.getSession();

        String password=request.getParameter("password");
        //头像
        String pptPic=request.getParameter("pptPic");
        //QQ邮箱
        String username=request.getParameter("username");

        UserService service=new UserServiceImpl();

        if(password.equals("")){
            int usersname= service.updateUsexiugair(username,pptPic);
            if(usersname==1){
                user ger= (user) session.getAttribute("usersList");
                ger.setUser_img(pptPic);
                session.setAttribute("usersList",ger);
                response.getWriter().append("相同");
            }else {
                response.getWriter().append("不相同相同");
            }
        }else {
            int users= service.updateUser(username,password,pptPic);
            if (users>=1){
                user userL= service.chaxunl(username);
                session.setAttribute("usersList", userL);
                response.getWriter().append("true");
            }else {
            response.getWriter().append("false");
            }
        }



    }




}
